package com.gxa.logistics.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.common.util.PageResultUtil;
import com.gxa.logistics.domain.dto.EmployeeReqListDTO;
import com.gxa.logistics.domain.dto.EmployeeSaveDTO;
import com.gxa.logistics.domain.dto.EmployeeUpdateDTO;
import com.gxa.logistics.domain.entity.Employee;
import com.gxa.logistics.domain.entity.User;
import com.gxa.logistics.domain.vo.EmployeeVO;
import com.gxa.logistics.mapper.EmployeeMapper;
import com.gxa.logistics.service.EmployeeService;
import com.gxa.logistics.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public RespResult<PageWrapperDTO<EmployeeVO>> list(EmployeeReqListDTO employeeReqListDTO) {
        // 使用分页插件
        PageHelper.startPage(employeeReqListDTO.getPageNo(), employeeReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<EmployeeVO> pageCommon = new PageWrapperDTO<>();
        List<EmployeeVO> employeeList = employeeMapper.findEmployeeByWhere(employeeReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(employeeList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void insertEmployee(EmployeeSaveDTO employeeSaveDTO) {
        employeeMapper.insertEmployee(employeeSaveDTO);
    }

    @Override
    public void updateEmployee(EmployeeUpdateDTO employeeUpdateDTO) {
        employeeMapper.updateEmployee(employeeUpdateDTO);
    }

    @Override
    public void deleteEmployeeById(Integer employeeId) {
        employeeMapper.deleteEmployeeById(employeeId);
    }

    @Override
    public void freezeEmployeeById(Integer employeeId) {
        employeeMapper.freezeEmployeeById(employeeId);
    }

    @Override
    public User findByUsername(String username) {
        return employeeMapper.findUserByUsername(username);
    }

    @Override
    public RespResult<List<EmployeeVO>> findById(Integer employeeId) {
        List<EmployeeVO> employeeVOS = employeeMapper.findById(employeeId);
        return RespResult.success(employeeVOS);
    }
}
